package com.aipanda.pojo;

import com.aipanda.pojo.SQLSequence.Direction;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;


/**页面概要类
 * @param list 分页信息集合
 * @param total 总记录数
 * @param pageable 分页信息
 * @author wanyuxiang
 *
 */
public class Page<T> implements Serializable {
	private static final long serialVersionUID = -2053800594583879853L;
	private final List<T> list = new ArrayList<T>();
	private final long total;
	private final Pageable pageable;

	public Page() {
		this.total = 0;
		this.pageable = new Pageable();
	}

	public Page(List<T> content, long total, Pageable pageable) {
		this.list.addAll(content);
		this.total = total;
		this.pageable = pageable;
	}

	/**
	 * 页码
	 * @return
	 */
	public int getPageNumber() {
		return this.pageable.getPageNumber();
	}

	/**
	 * 每页记录数
	 * @return
	 */
	public int getPageSize() {
		return this.pageable.getPageSize();
	}
	/**
	 * 搜索属性
	 * @return
	 */
	public String getSearchProperty() {
		return this.pageable.getSearchProperty();
	}
	/**
	 * 搜索值
	 * @return
	 */
	public String getSearchValue() {
		return this.pageable.getSearchValue();
	}
	/**
	 * 排序属性
	 * @return
	 */
	public String getOrderProperty() {
		return this.pageable.getOrderProperty();
	}
	/**
	 * 排序方向
	 * @return
	 */
	public Direction getOrderDirection() {
		return this.pageable.getOrderDirection();
	}
	/**
	 * 排序
	 * @return
	 */
	public List<SQLSequence> getOrders() {
		return this.pageable.getOrders();
	}
	/**
	 * 筛选
	 * @return
	 */
	public List<SQLCondition> getFilters() {
		return this.pageable.getFilters();
	}
	/**
	 * 总页数
	 * @return
	 */
	public int getTotalPages() {
		return (int) Math.ceil((double)getTotal() / getPageSize());
	}
	/**
	 * 内容
	 * @return
	 */
	public List<T> getContent() {
		return this.list;
	}
	/**
	 * 总记录数
	 * @return
	 */
	public long getTotal() {
		return this.total;
	}
	/**
	 * 分页信息
	 * @return
	 */
	public Pageable getPageable() {
		return this.pageable;
	}
}
